/*
 * uart.h
 * $HeadURL: http://bldc-motor.googlecode.com/svn/trunk/Software/usart.h $
 * $Revision: 7 $
 *
 * Created: 29.08.2012 11:19:42
 * $LastChangedDate: 2012-08-30 15:11:54 +0000 (Thu, 30 Aug 2012) $
 *
 *  Author: Jens
 * $Author: boecki91@gmail.com $
 *
 * File based on
 * Title:    Interrupt UART library with receive/transmit circular buffers
 * Author:   Peter Fleury <pfleury@gmx.ch>   http://jump.to/fleury
 */ 

#ifndef UART_H_
#define UART_H_

#define UART_BAUD_SELECT(BaudRate,F_cpu) ((F_cpu)/((BaudRate)*16l)-1)
/* size of RX/TX buffers */
#define UART_RX_BUFFER_SIZE 32
#define UART_TX_BUFFER_SIZE 32


#define UART_RX_BUFFER_MASK ( UART_RX_BUFFER_SIZE - 1)
#define UART_TX_BUFFER_MASK ( UART_TX_BUFFER_SIZE - 1)

#if ( UART_RX_BUFFER_SIZE & UART_RX_BUFFER_MASK )
#error RX Buffer ist keine 2er Potenz
#endif
#if ( UART_TX_BUFFER_SIZE & UART_TX_BUFFER_MASK )
#error TX Buffer ist keine 2er Potenz
#endif

static volatile unsigned char UART_TxBuf[UART_TX_BUFFER_SIZE];
static volatile unsigned char UART_RxBuf[UART_RX_BUFFER_SIZE];
static volatile unsigned char UART_TxHead;
static volatile unsigned char UART_TxTail;
static volatile unsigned char UART_RxHead;
static volatile unsigned char UART_RxTail;





void USART_init (unsigned int ubbr);
void USART_putc( unsigned char data );
void USART_puts(const char *s );
void USART_puti(int16_t integer);
unsigned int USART_getc(void);



#endif /* UART_H_ */